#define _CRT_SECURE_NO_WARNINGS 1
//void LTPopBack(LTNode* phead)
//{
//	assert(phead);
//	assert(phead->next != phead);
//	LTNode* end = phead->prev;
//	LTNode* prev_end = end->prev;
//	prev_end->next = phead;
//	phead->prev = prev_end;
//	free(end);
//}
#include<stdio.h>
#include<assert.h>
int cmp_int(const void* s1, const void* s2)
{
    return *((int*)s1) - *((int*)s2);
}
int two(int* numbers, int order, int numbersLen)
{
    int left = 0;
    int right = numbersLen - 1;
    int mid = (left + right) / 2;
    while (left <= right)
    {
        mid = (left + right) / 2;
        if (order > numbers[mid])
        {
            left = mid + 1;

        }
        else if (order < numbers[mid])
        {
            right = mid - 1;
        }
        else
        {
            return mid;
        }
    }
    return -1;
}
int* twoSum(int* numbers, int numbersLen, int target, int* returnSize) {
    int i = 0;
    *returnSize = 2;
    qsort(numbers, numbersLen, sizeof(int), cmp_int);
    int* arr = (int*)malloc(sizeof(int) * 2);
    for (i = 0; i < numbersLen; i++)
    {
        int order = target - numbers[i];
        int end = two(numbers, order, numbersLen);
        if (end != -1)
        {
            if (arr[i] > arr[end])
            {
                arr[0] = numbers[end];
                arr[1] = numbers[i];
            }
            else
            {
                arr[0] = numbers[i];
                arr[1] = numbers[end];
            }
            return arr;
        }
    }
    return arr;
}
int main()
{
    int arr1[3] = { 3,2,4 };
    int r = 0;
    int*arr2=twoSum(arr1,3,6,&r);
    for (int i = 0; i < r; i++)
    {
        printf("%d ", arr2[i]);
    }
}